package com.qf.efserver.alarm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.common.core.entity.SleepSchedule;
import com.qf.efserver.alarm.mapper.SleepScheduleMapper;
import com.qf.efserver.alarm.service.SleepScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class SleepScheduleServiceImpl implements SleepScheduleService {

    @Resource
   private SleepScheduleMapper sleepScheduleMapper;

    /**
     * 保存闹钟
     * @param sleepSchedule
     */
    @Override
    public void save(SleepSchedule sleepSchedule) {
        sleepScheduleMapper.insert(sleepSchedule);
    }

    /**
     * 查询有效的闹钟
     * @return 状态列表
     */
    @Override
    public List<SleepSchedule> findValidAlarms() {

        List<SleepSchedule> status = sleepScheduleMapper.selectList(new QueryWrapper<SleepSchedule>().eq("status", 1));
        return status;
    }

    /**
     * 查询过期的闹钟
     * @return 过期闹钟的列表
     */
    @Override
    public List<SleepSchedule> findExpiredAlarms() {
        Date now = new Date();
        List<SleepSchedule> sleepSchedules = sleepScheduleMapper.selectList(new QueryWrapper<SleepSchedule>().lt("end_date", now).eq("status", 1));

        return sleepSchedules;
    }

    /**
     * 更新闹钟
     * @param sleepSchedule
     */
    @Override
    public void update(SleepSchedule sleepSchedule) {
    sleepScheduleMapper.updateById(sleepSchedule);
    }
}
